package org.csmzxy.class2333;
import java.util.concurrent.*;
class MyRunnable02 implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() +
                "执行任务!");
    }
}
public class Example07 {
    public static void main(String[] args) {
        // 创建线程池对象
        ExecutorService pool = new ThreadPoolExecutor(2, 4, 6,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(2),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        // 创建Runnable任务，交由线程池处理
        Runnable target = new MyRunnable02();
        for (int i = 0; i < 5; i++) {
            // 执行任务
            pool.execute(target);
        }
    }
}